﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GenerateAdminPage.Classes.Views
{
    #region USING
    using GenerateAdminPage.Classes.DBStructure;
    using GenerateAdminPage.Classes.Helpers;
    #endregion

    public class ViewComplexes : AbstractViews
    {
        public override string GenerateFields()
        {
            StringBuilder Result = new StringBuilder();

            Result.AppendLine(TAB2 + "private System.Windows.Forms.Panel panel1;");
            Result.AppendLine(TAB2 + "private System.Windows.Forms.Panel panel2;");
            Result.AppendLine(TAB2 + "private System.Windows.Forms.Panel panel3;");
            Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.LabelX lblTitle;");

            Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.LabelX lblDanhSach;");
            Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.ButtonX btnCapNhat;");
            Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.ButtonX btnThoat;");
            Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.ButtonX btnXoa;");
            Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.ButtonX btnThem;");
            Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.Controls.DataGridViewX dtgvData;");

            for (int i = 0; i < TblOne.Attributes.Count; i++)
            {
                if (!(TblOne.Attributes[i].IsForeignKey && GlobalVariables.g_sTableNguoiDung.Contains(TblOne.Attributes[i].ReferTo)))
                {
                    Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.LabelX lbl" + TblOne.Attributes[i].Name + ";");   
                }
            }

            for (int i = 0; i < TblOne.Attributes.Count; i++)
            {
                if (TblOne.Attributes[i].IsForeignKey)
                {
                    if (!GlobalVariables.g_sTableNguoiDung.Contains(TblOne.Attributes[i].ReferTo))
                    {
                        Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.Controls.TextBoxX txt" + TblOne.Attributes[i].ReferTo + ";");
                        Result.AppendLine(TAB2 + "private System.Windows.Forms.Button btnChon" + TblOne.Attributes[i].ReferTo + ";");
                    }
                }
                else
                {
                    if (TblOne.Attributes[i].Type == DataType.DATETIME)
                    {
                        Result.AppendLine(TAB2 + "private DevComponents.Editors.DateTimeAdv.DateTimeInput dt" + TblOne.Attributes[i].Name + ";");
                    }
                    else if (TblOne.Attributes[i].Type == DataType.BOOL)
                    {
                        Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.Controls.ComboBoxEx cbx" + TblOne.Attributes[i].Name + ";");
                    }
                    else if (TblOne.Attributes[i].Type == DataType.IMAGE)
                    {
                        Result.AppendLine(TAB2 + "private System.Windows.Forms.PictureBox ptb" + TblOne.Attributes[i].Name + ";");
                        Result.AppendLine(TAB2 + "private System.Windows.Forms.Button btnChon" + TblOne.Attributes[i].Name + ";");
                        Result.AppendLine(TAB2 + "private System.Windows.Forms.Button btnXoa" + TblOne.Attributes[i].Name + ";");
                        Result.AppendLine(TAB2 + "private System.Windows.Forms.OpenFileDialog openFileDialog1;");
                    }
                    else
                    {
                        Result.AppendLine(TAB2 + "private DevComponents.DotNetBar.Controls.TextBoxX txt" + TblOne.Attributes[i].Name + ";");
                    }
                }
            }

            return Result.ToString();
        }

        public override string GenerateInitializeComponent()
        {
            StringBuilder Result = new StringBuilder();
            var IsFKIsNguoiDung = false;

            Result.AppendLine(TAB2 + "private void InitializeComponent()");
            Result.AppendLine(TAB2 + "{");
            Result.AppendLine(TAB3 + "System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();");

            if (GlobalVariables.g_colComplex.Keys.Contains(TblOne.Name))
            {
                Result.AppendLine(TAB3 + "System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmLap" + TblOne.Name + "));");
            }
            else
            {
                Result.AppendLine(TAB3 + "System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmQuanLy" + TblOne.Name + "));");
            }

            Result.AppendLine(TAB3 + "this.panel1 = new System.Windows.Forms.Panel();");
            Result.AppendLine(TAB3 + "this.panel2 = new System.Windows.Forms.Panel();");
            Result.AppendLine(TAB3 + "this.panel3 = new System.Windows.Forms.Panel();");
            Result.AppendLine(TAB3 + "this.dtgvData = new DevComponents.DotNetBar.Controls.DataGridViewX();");
            Result.AppendLine(TAB3 + "this.lblDanhSach = new DevComponents.DotNetBar.LabelX();");
            Result.AppendLine(TAB3 + "this.lblTitle = new DevComponents.DotNetBar.LabelX();");
            Result.AppendLine(TAB3 + "this.btnXoa = new DevComponents.DotNetBar.ButtonX();");
            Result.AppendLine(TAB3 + "this.btnThem = new DevComponents.DotNetBar.ButtonX();");
            Result.AppendLine(TAB3 + "this.btnCapNhat = new DevComponents.DotNetBar.ButtonX();");
            Result.AppendLine(TAB3 + "this.btnThoat = new DevComponents.DotNetBar.ButtonX();");

            var count = 0;
            for (int i = 0; i < TblOne.Attributes.Count; i++)
            {
                if (TblOne.Attributes[i].IsForeignKey)
                {
                    if (!GlobalVariables.g_sTableNguoiDung.Contains(TblOne.Attributes[i].ReferTo))
                    {
                        Result.AppendLine(TAB3 + "this.lbl" + TblOne.Attributes[i].Name + " = new DevComponents.DotNetBar.LabelX();");
                        Result.AppendLine(TAB3 + "this.txt" + TblOne.Attributes[i].ReferTo + " = new DevComponents.DotNetBar.Controls.TextBoxX();");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].ReferTo + " = new System.Windows.Forms.Button();");
                    }
                    else
                    {
                        IsFKIsNguoiDung = true;
                    }
                }
                else
                {
                    Result.AppendLine(TAB3 + "this.lbl" + TblOne.Attributes[i].Name + " = new DevComponents.DotNetBar.LabelX();");
                    if (TblOne.Attributes[i].Type == DataType.DATETIME)
                    {
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + " = new DevComponents.Editors.DateTimeAdv.DateTimeInput();");
                    }
                    else if (TblOne.Attributes[i].Type == DataType.BOOL)
                    {
                        Result.AppendLine(TAB3 + "this.cbx" + TblOne.Attributes[i].Name + " = new DevComponents.DotNetBar.Controls.ComboBoxEx();");
                    }
                    else if (TblOne.Attributes[i].Type == DataType.IMAGE)
                    {
                        Result.AppendLine(TAB3 + "this.ptb" + TblOne.Attributes[i].Name + " = new System.Windows.Forms.PictureBox();");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].Name + " = new System.Windows.Forms.Button();");
                        Result.AppendLine(TAB3 + "this.btnXoa" + TblOne.Attributes[i].Name + " = new System.Windows.Forms.Button();");
                        
                        if (count == 0)
                        {
                            Result.AppendLine(TAB3 + "this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();");
                            count++;
                        }
                    }
                    else
                    {
                        Result.AppendLine(TAB3 + "this.txt" + TblOne.Attributes[i].Name + " = new DevComponents.DotNetBar.Controls.TextBoxX();");
                    }
                }
            }

            Result.AppendLine(TAB3 + "this.panel1.SuspendLayout();");
            Result.AppendLine(TAB3 + "this.panel2.SuspendLayout();");
            Result.AppendLine(TAB3 + "this.panel3.SuspendLayout();");
            Result.AppendLine(TAB3 + "((System.ComponentModel.ISupportInitialize)(this.dtgvData)).BeginInit();");
            Result.AppendLine(TAB3 + "this.SuspendLayout();");
            Result.AppendLine(TAB3 + "this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(217)))), ((int)(((byte)(247)))));");
            Result.AppendLine(TAB3 + "this.panel1.Controls.Add(this.panel3);");
            Result.AppendLine(TAB3 + "this.panel1.Controls.Add(this.panel2);");
            Result.AppendLine(TAB3 + "this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;");
            Result.AppendLine(TAB3 + "this.panel1.Location = new System.Drawing.Point(0, 0);");
            Result.AppendLine(TAB3 + "this.panel1.Name = \"panel1\";");

            int panel1Size = 449;
            if ((double)TblOne.Attributes.Count >= 3)
            {
                panel1Size += OFFSET_Y * (TblOne.Attributes.Count - (IsFKIsNguoiDung ? 1 : 0) - 3);
            }
            Result.AppendLine(TAB3 + "this.panel1.Size = new System.Drawing.Size(733, " + panel1Size + ");");
            Result.AppendLine(TAB3 + "this.panel1.TabIndex = 3;" + END);

            Result.AppendLine(TAB3 + "this.lblTitle.AutoSize = true;");
            Result.AppendLine(TAB3 + "this.lblTitle.Font = new System.Drawing.Font(\"Microsoft Sans Serif\", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));");
            Result.AppendLine(TAB3 + "this.lblTitle.ForeColor = System.Drawing.Color.Crimson;");
            Result.AppendLine(TAB3 + "this.lblTitle.Location = new System.Drawing.Point(318, 3);");
            Result.AppendLine(TAB3 + "this.lblTitle.Name = \"lblTitle\";");
            Result.AppendLine(TAB3 + "this.lblTitle.Size = new System.Drawing.Size(105, 19);");
            Result.AppendLine(TAB3 + "this.lblTitle.TabIndex = 1;");

            if (GlobalVariables.g_colComplex.Keys.Contains(TblOne.Name))
            {
                Result.AppendLine(TAB3 + "this.lblTitle.Text = \"Lập " + TblOne.Name + "\";" + END);
            }
            else
            {
                Result.AppendLine(TAB3 + "this.lblTitle.Text = \"Quản lý " + TblOne.Name + "\";"+ END);
            }


            int firstLabelY = 37;
            int firstTextboxY = 40;
            count = 0;
            for (int i = 0; i < TblOne.Attributes.Count; i++)
            {
                if (TblOne.Attributes[i].IsForeignKey)
                {
                    if (!GlobalVariables.g_sTableNguoiDung.Contains(TblOne.Attributes[i].ReferTo))
                    {
                        if (i != 0)
                        {
                            firstLabelY += OFFSET_Y;
                            firstTextboxY += OFFSET_Y;
                        }

                        Result.AppendLine(TAB3 + "this.lbl" + TblOne.Attributes[i].Name + ".Font = new System.Drawing.Font(\"Microsoft Sans Serif\", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));");
                        Result.AppendLine(TAB3 + "this.lbl" + TblOne.Attributes[i].Name + ".Location = new System.Drawing.Point(44, " + firstLabelY.ToString() + ");");
                        Result.AppendLine(TAB3 + "this.lbl" + TblOne.Attributes[i].Name + ".Name = \"labelX" + (i + 1) + "\";");
                        Result.AppendLine(TAB3 + "this.lbl" + TblOne.Attributes[i].Name + ".Size = new System.Drawing.Size(89, 23);");
                        Result.AppendLine(TAB3 + "this.lbl" + TblOne.Attributes[i].Name + ".TabIndex = 100;");
                        Result.AppendLine(TAB3 + "this.lbl" + TblOne.Attributes[i].Name + ".Text = \"" + TblOne.Attributes[i].Name + "\";" + END);

                        Result.AppendLine(TAB3 + "this.txt" + TblOne.Attributes[i].ReferTo + ".Border.Class = \"TextBoxBorder\";");
                        Result.AppendLine(TAB3 + "this.txt" + TblOne.Attributes[i].ReferTo + ".Location = new System.Drawing.Point(142, " + firstTextboxY.ToString() + ");");
                        Result.AppendLine(TAB3 + "this.txt" + TblOne.Attributes[i].ReferTo + ".Name = \"txt" + TblOne.Attributes[i].ReferTo + "\";");
                        Result.AppendLine(TAB3 + "this.txt" + TblOne.Attributes[i].ReferTo + ".ReadOnly = true;");
                        Result.AppendLine(TAB3 + "this.txt" + TblOne.Attributes[i].ReferTo + ".Size = new System.Drawing.Size(310, 20);");
                        Result.AppendLine(TAB3 + "this.txt" + TblOne.Attributes[i].ReferTo + ".TabIndex = " + i.ToString() + ";" + END);

                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].ReferTo + ".BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].ReferTo + ".Image = ((System.Drawing.Image)(resources.GetObject(\"btnChonThamChieu.Image\")));");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].ReferTo + ".Location = new System.Drawing.Point(" + (142 + 310 + 6).ToString() + ", " + (firstTextboxY - 5).ToString() + ");");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].ReferTo + ".Name = \"btnChon" + TblOne.Attributes[i].ReferTo + "\";");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].ReferTo + ".Size = new System.Drawing.Size(28, 27);");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].ReferTo + ".UseVisualStyleBackColor = true;");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].ReferTo + ".Click += new System.EventHandler(this.btnChon" + TblOne.Attributes[i].ReferTo + "_Click);");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].ReferTo + ".TabIndex = " + i.ToString() + ";" + END);
                    }
                }
                else
                {
                    if (i != 0)
                    {
                        firstLabelY += OFFSET_Y;
                        firstTextboxY += OFFSET_Y;
                    }

                    Result.AppendLine(TAB3 + "this.lbl" + TblOne.Attributes[i].Name + ".Font = new System.Drawing.Font(\"Microsoft Sans Serif\", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));");
                    Result.AppendLine(TAB3 + "this.lbl" + TblOne.Attributes[i].Name + ".Location = new System.Drawing.Point(44, " + firstLabelY.ToString() + ");");
                    Result.AppendLine(TAB3 + "this.lbl" + TblOne.Attributes[i].Name + ".Name = \"labelX" + (i + 1) + "\";");
                    Result.AppendLine(TAB3 + "this.lbl" + TblOne.Attributes[i].Name + ".Size = new System.Drawing.Size(89, 23);");
                    Result.AppendLine(TAB3 + "this.lbl" + TblOne.Attributes[i].Name + ".TabIndex = 100;");
                    Result.AppendLine(TAB3 + "this.lbl" + TblOne.Attributes[i].Name + ".Text = \"" + TblOne.Attributes[i].Name + "\";" + END);

                    if (TblOne.Attributes[i].Type == DataType.DATETIME)
                    {
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".BackgroundStyle.Class = \"DateTimeInputBackground\";");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".ButtonDropDown.Visible = true;");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".CustomFormat = \"dd/MM/yyyy\";");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".Format = DevComponents.Editors.eDateTimePickerFormat.Custom;");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".Location = new System.Drawing.Point(142, " + firstTextboxY.ToString() + ");");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".MonthCalendar.AnnuallyMarkedDates = new System.DateTime[0];");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".MonthCalendar.BackgroundStyle.BackColor = System.Drawing.SystemColors.Window;");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".MonthCalendar.ClearButtonVisible = true;");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".MonthCalendar.CommandsBackgroundStyle.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground2;");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".MonthCalendar.CommandsBackgroundStyle.BackColorGradientAngle = 90;");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".MonthCalendar.CommandsBackgroundStyle.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground;");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".MonthCalendar.CommandsBackgroundStyle.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid;");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".MonthCalendar.CommandsBackgroundStyle.BorderTopColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarDockedBorder;");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".MonthCalendar.CommandsBackgroundStyle.BorderTopWidth = 1;");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".MonthCalendar.MarkedDates = new System.DateTime[0];");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".MonthCalendar.MonthlyMarkedDates = new System.DateTime[0];");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".MonthCalendar.NavigationBackgroundStyle.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2;");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".MonthCalendar.NavigationBackgroundStyle.BackColorGradientAngle = 90;");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".MonthCalendar.NavigationBackgroundStyle.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground;");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".MonthCalendar.TodayButtonVisible = true;");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".Name = \"dt" + TblOne.Attributes[i].Name + "\";");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".Size = new System.Drawing.Size(182, 20);");
                        Result.AppendLine(TAB3 + "this.dt" + TblOne.Attributes[i].Name + ".TabIndex = " + i.ToString() + ";" + END);
                    }
                    else if (TblOne.Attributes[i].Type == DataType.BOOL)
                    {
                        Result.AppendLine(TAB3 + "this.cbx" + TblOne.Attributes[i].Name + ".DisplayMember = \"Text\";");
                        Result.AppendLine(TAB3 + "this.cbx" + TblOne.Attributes[i].Name + ".DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;");
                        Result.AppendLine(TAB3 + "this.cbx" + TblOne.Attributes[i].Name + ".FormattingEnabled = true;");
                        Result.AppendLine(TAB3 + "this.cbx" + TblOne.Attributes[i].Name + ".ItemHeight = 14;");
                        Result.AppendLine(TAB3 + "this.cbx" + TblOne.Attributes[i].Name + ".Location = new System.Drawing.Point(142, " + firstTextboxY.ToString() + ");");
                        Result.AppendLine(TAB3 + "this.cbx" + TblOne.Attributes[i].Name + ".Name = \"cbx" + TblOne.Attributes[i].Name + "\";");
                        Result.AppendLine(TAB3 + "this.cbx" + TblOne.Attributes[i].Name + ".Size = new System.Drawing.Size(114, 20);");
                        Result.AppendLine(TAB3 + "this.cbx" + TblOne.Attributes[i].Name + ".TabIndex = " + i.ToString() + ";" + END);
                    }
                    else if (TblOne.Attributes[i].Type == DataType.IMAGE)
                    {
                        if (count == 0)
                        {
                            Result.AppendLine(TAB3 + "this.openFileDialog1.FileName = \"openFileDialog1\";");
                            count++;
                        }

                        Result.AppendLine(TAB3 + "this.ptb" + TblOne.Attributes[i].Name + ".Anchor = System.Windows.Forms.AnchorStyles.Top;");
                        Result.AppendLine(TAB3 + "this.ptb" + TblOne.Attributes[i].Name + ".BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;");
                        Result.AppendLine(TAB3 + "this.ptb" + TblOne.Attributes[i].Name + ".InitialImage = null;");
                        Result.AppendLine(TAB3 + "this.ptb" + TblOne.Attributes[i].Name + ".Location = new System.Drawing.Point(142, " + firstTextboxY.ToString() + ");");
                        Result.AppendLine(TAB3 + "this.ptb" + TblOne.Attributes[i].Name + ".Name = \"ptb" + TblOne.Attributes[i].Name + "\";");
                        Result.AppendLine(TAB3 + "this.ptb" + TblOne.Attributes[i].Name + ".Size = new System.Drawing.Size(148, 91);");
                        Result.AppendLine(TAB3 + "this.ptb" + TblOne.Attributes[i].Name + ".SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;");
                        Result.AppendLine(TAB3 + "this.ptb" + TblOne.Attributes[i].Name + ".TabStop = false;");

                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].Name + ".BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].Name + ".Image = ((System.Drawing.Image)(resources.GetObject(\"btnChonThamChieu.Image\")));");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].Name + ".Location = new System.Drawing.Point(" + (142 + 148 + 6).ToString() + ", " + (firstTextboxY - 5).ToString() + ");");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].Name + ".Name = \"btnChon" + TblOne.Attributes[i].Name + "\";");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].Name + ".Size = new System.Drawing.Size(28, 27);");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].Name + ".UseVisualStyleBackColor = true;");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].Name + ".Click += new System.EventHandler(this.btnChon" + TblOne.Attributes[i].Name + "_Click);");
                        Result.AppendLine(TAB3 + "this.btnChon" + TblOne.Attributes[i].Name + ".TabIndex = " + i.ToString() + ";" + END);

                        Result.AppendLine(TAB3 + "this.btnXoa" + TblOne.Attributes[i].Name + ".BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;");
                        Result.AppendLine(TAB3 + "this.btnXoa" + TblOne.Attributes[i].Name + ".Image = ((System.Drawing.Image)(resources.GetObject(\"btnXoa.Image\")));");
                        Result.AppendLine(TAB3 + "this.btnXoa" + TblOne.Attributes[i].Name + ".Location = new System.Drawing.Point(" + (142 + 148 + 6).ToString() + ", " + (firstTextboxY - 5).ToString() + ");");
                        Result.AppendLine(TAB3 + "this.btnXoa" + TblOne.Attributes[i].Name + ".Name = \"btnXoa" + TblOne.Attributes[i].Name + "\";");
                        Result.AppendLine(TAB3 + "this.btnXoa" + TblOne.Attributes[i].Name + ".Size = new System.Drawing.Size(28, 27);");
                        Result.AppendLine(TAB3 + "this.btnXoa" + TblOne.Attributes[i].Name + ".UseVisualStyleBackColor = true;");
                        Result.AppendLine(TAB3 + "this.btnXoa" + TblOne.Attributes[i].Name + ".Click += new System.EventHandler(this.btnXoa" + TblOne.Attributes[i].Name + "_Click);");
                    }
                    else
                    {
                        Result.AppendLine(TAB3 + "this.txt" + TblOne.Attributes[i].Name + ".Border.Class = \"TextBoxBorder\";");
                        Result.AppendLine(TAB3 + "this.txt" + TblOne.Attributes[i].Name + ".Location = new System.Drawing.Point(142, " + firstTextboxY.ToString() + ");");
                        Result.AppendLine(TAB3 + "this.txt" + TblOne.Attributes[i].Name + ".Name = \"txt" + TblOne.Attributes[i].Name + "\";");

                        if (TblOne.Attributes[i].IsPrimaryKey && TblOne.Attributes[i].IsIdentify)
                        {
                            Result.AppendLine(TAB3 + "this.txt" + TblOne.Attributes[i].Name + ".ReadOnly = true;");
                        }

                        Result.AppendLine(TAB3 + "this.txt" + TblOne.Attributes[i].Name + ".Size = new System.Drawing.Size(310, 20);");
                        Result.AppendLine(TAB3 + "this.txt" + TblOne.Attributes[i].Name + ".TabIndex = " + i.ToString() + ";" + END);
                    }
                }
            }

            Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.lblTitle);");

            for (int i = 0; i < TblOne.Attributes.Count; i++)
            {
                if (TblOne.Attributes[i].IsForeignKey)
                {
                    if (!GlobalVariables.g_sTableNguoiDung.Contains(TblOne.Attributes[i].ReferTo))
                    {
                        Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.lbl" + TblOne.Attributes[i].Name + ");");
                        Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.txt" + TblOne.Attributes[i].ReferTo + ");");
                        Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.btnChon" + TblOne.Attributes[i].ReferTo + ");");
                    }
                }
                else
                {
                    Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.lbl" + TblOne.Attributes[i].Name + ");");
                    if (TblOne.Attributes[i].Type == DataType.DATETIME)
                    {
                        Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.dt" + TblOne.Attributes[i].Name + ");");
                    }
                    else if (TblOne.Attributes[i].Type == DataType.BOOL)
                    {
                        Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.cbx" + TblOne.Attributes[i].Name + ");");
                    }
                    else if (TblOne.Attributes[i].Type == DataType.IMAGE)
                    {
                        Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.ptb" + TblOne.Attributes[i].Name + ");");
                        Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.btnChon" + TblOne.Attributes[i].Name + ");");
                        Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.btnXoa" + TblOne.Attributes[i].Name + ");");
                    }
                    else
                    {
                        Result.AppendLine(TAB3 + "this.panel2.Controls.Add(this.txt" + TblOne.Attributes[i].Name + ");");
                    }
                }
            }

            Result.AppendLine(TAB3 + "this.panel2.Dock = System.Windows.Forms.DockStyle.Top;");
            Result.AppendLine(TAB3 + "this.panel2.Location = new System.Drawing.Point(0, 0);");
            Result.AppendLine(TAB3 + "this.panel2.Name = \"panel2\";");

            int panel2Size = 123;
            if ((double)TblOne.Attributes.Count >= 3)
            {
                panel2Size += OFFSET_Y * (TblOne.Attributes.Count - (IsFKIsNguoiDung ? 1 : 0) - 3);
            }

            Result.AppendLine(TAB3 + "this.panel2.Size = new System.Drawing.Size(733, " + panel2Size + ");");
            Result.AppendLine(TAB3 + "this.panel2.TabIndex = 335;" + END);

            Result.AppendLine(TAB3 + "this.panel3.Controls.Add(this.btnCapNhat);");
            Result.AppendLine(TAB3 + "this.panel3.Controls.Add(this.dtgvData);");
            Result.AppendLine(TAB3 + "this.panel3.Controls.Add(this.btnThoat);");
            Result.AppendLine(TAB3 + "this.panel3.Controls.Add(this.btnXoa);");
            Result.AppendLine(TAB3 + "this.panel3.Controls.Add(this.btnThem);");
            Result.AppendLine(TAB3 + "this.panel3.Controls.Add(this.lblDanhSach);");
            Result.AppendLine(TAB3 + "this.panel3.Dock = System.Windows.Forms.DockStyle.Fill;");
            Result.AppendLine(TAB3 + "this.panel3.Location = new System.Drawing.Point(0, 123);");
            Result.AppendLine(TAB3 + "this.panel3.Name = \"panel3\";");
            Result.AppendLine(TAB3 + "this.panel3.Size = new System.Drawing.Size(733, 326);");
            Result.AppendLine(TAB3 + "this.panel3.TabIndex = 336;" + END);

            Result.AppendLine(TAB3 + "this.dtgvData.AllowUserToAddRows = false;");
            Result.AppendLine(TAB3 + "this.dtgvData.BackgroundColor = System.Drawing.Color.White;");
            Result.AppendLine(TAB3 + "this.dtgvData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;");
            Result.AppendLine(TAB3 + "dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;");
            Result.AppendLine(TAB3 + "dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Window;");
            Result.AppendLine(TAB3 + "dataGridViewCellStyle1.Font = new System.Drawing.Font(\"Microsoft Sans Serif\", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));");
            Result.AppendLine(TAB3 + "dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.ControlText;");
            Result.AppendLine(TAB3 + "dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;");
            Result.AppendLine(TAB3 + "dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.ControlText;");
            Result.AppendLine(TAB3 + "dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.False;");
            Result.AppendLine(TAB3 + "this.dtgvData.DefaultCellStyle = dataGridViewCellStyle1;");
            Result.AppendLine(TAB3 + "this.dtgvData.GridColor = System.Drawing.Color.FromArgb(((int)(((byte)(208)))), ((int)(((byte)(215)))), ((int)(((byte)(229)))));");
            Result.AppendLine(TAB3 + "this.dtgvData.Location = new System.Drawing.Point(142, 39);");
            Result.AppendLine(TAB3 + "this.dtgvData.Name = \"dtgvData\";");
            Result.AppendLine(TAB3 + " this.dtgvData.ReadOnly = true;");
            Result.AppendLine(TAB3 + "this.dtgvData.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;");
            Result.AppendLine(TAB3 + "this.dtgvData.Size = new System.Drawing.Size(580, 236);");
            Result.AppendLine(TAB3 + "this.dtgvData.TabIndex = 334;" + END);

            Result.AppendLine(TAB3 + "this.btnXoa.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;");
            Result.AppendLine(TAB3 + "this.btnXoa.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;");
            Result.AppendLine(TAB3 + "this.btnXoa.Image = ((System.Drawing.Image)(resources.GetObject(\"btnXoa.Image\")));");
            Result.AppendLine(TAB3 + "this.btnXoa.ImageFixedSize = new System.Drawing.Size(16, 16);");
            Result.AppendLine(TAB3 + "this.btnXoa.Location = new System.Drawing.Point(318, 6);");
            Result.AppendLine(TAB3 + "this.btnXoa.Name = \"btnXoa\";");
            Result.AppendLine(TAB3 + "this.btnXoa.Size = new System.Drawing.Size(168, 23);");
            Result.AppendLine(TAB3 + "this.btnXoa.TabIndex = 329;");
            Result.AppendLine(TAB3 + "this.btnXoa.Text = \"Xóa khỏi danh sách\";");
            Result.AppendLine(TAB3 + "this.btnXoa.Click += new System.EventHandler(this.btnXoa_Click);" + END);

            Result.AppendLine(TAB3 + "this.btnThem.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;");
            Result.AppendLine(TAB3 + "this.btnThem.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;");
            Result.AppendLine(TAB3 + "this.btnThem.Image = ((System.Drawing.Image)(resources.GetObject(\"btnThem.Image\")));");
            Result.AppendLine(TAB3 + "this.btnThem.ImageFixedSize = new System.Drawing.Size(16, 16);");
            Result.AppendLine(TAB3 + "this.btnThem.Location = new System.Drawing.Point(142, 6);");
            Result.AppendLine(TAB3 + "this.btnThem.Name = \"btnThem\";");
            Result.AppendLine(TAB3 + "this.btnThem.Size = new System.Drawing.Size(168, 23);");
            Result.AppendLine(TAB3 + "this.btnThem.TabIndex = 325;");
            Result.AppendLine(TAB3 + "this.btnThem.Text = \"Thêm vào danh sách\";");
            Result.AppendLine(TAB3 + "this.btnThem.Click += new System.EventHandler(this.btnThem_Click);" + END);

            Result.AppendLine(TAB3 + "this.lblDanhSach.Font = new System.Drawing.Font(\"Microsoft Sans Serif\", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));");
            Result.AppendLine(TAB3 + "this.lblDanhSach.Location = new System.Drawing.Point(5, 39);");
            Result.AppendLine(TAB3 + "this.lblDanhSach.Name = \"lblDanhSach\";");
            Result.AppendLine(TAB3 + "this.lblDanhSach.Size = new System.Drawing.Size(127, 23);");
            Result.AppendLine(TAB3 + "this.lblDanhSach.TabIndex = 97;");
            Result.AppendLine(TAB3 + "this.lblDanhSach.Text = \"Danh sách " + TblOne.Name + "\";");
            Result.AppendLine(TAB3 + "this.lblDanhSach.TextAlignment = System.Drawing.StringAlignment.Far;" + END);

            Result.AppendLine(TAB3 + "this.btnCapNhat.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;");
            Result.AppendLine(TAB3 + "this.btnCapNhat.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;");
            Result.AppendLine(TAB3 + "this.btnCapNhat.Image = ((System.Drawing.Image)(resources.GetObject(\"btnCapNhat.Image\")));");
            Result.AppendLine(TAB3 + "this.btnCapNhat.ImageFixedSize = new System.Drawing.Size(16, 16);");
            Result.AppendLine(TAB3 + "this.btnCapNhat.Location = new System.Drawing.Point(552, 289);");
            Result.AppendLine(TAB3 + "this.btnCapNhat.Name = \"btnCapNhat\";");
            Result.AppendLine(TAB3 + "this.btnCapNhat.Size = new System.Drawing.Size(64, 23);");
            Result.AppendLine(TAB3 + "this.btnCapNhat.TabIndex = 43;");
            Result.AppendLine(TAB3 + "this.btnCapNhat.Text = \"Ghi\";");
            Result.AppendLine(TAB3 + "this.btnCapNhat.Click += new System.EventHandler(this.btnCapNhat_Click);" + END);

            Result.AppendLine(TAB3 + "this.btnThoat.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;");
            Result.AppendLine(TAB3 + "this.btnThoat.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;");
            Result.AppendLine(TAB3 + "this.btnThoat.Image = ((System.Drawing.Image)(resources.GetObject(\"btnThoat.Image\")));");
            Result.AppendLine(TAB3 + "this.btnThoat.ImageFixedSize = new System.Drawing.Size(16, 16);");
            Result.AppendLine(TAB3 + "this.btnThoat.Location = new System.Drawing.Point(634, 289);");
            Result.AppendLine(TAB3 + "this.btnThoat.Name = \"btnThoat\";");
            Result.AppendLine(TAB3 + "this.btnThoat.Size = new System.Drawing.Size(72, 23);");
            Result.AppendLine(TAB3 + "this.btnThoat.TabIndex = 40;");
            Result.AppendLine(TAB3 + "this.btnThoat.Text = \"Thoát\";");
            Result.AppendLine(TAB3 + "this.btnThoat.Click += new System.EventHandler(this.btnThoat_Click);" + END);

            int ClientSize = 449;
            if ((double)TblOne.Attributes.Count >= 3)
            {
                ClientSize += OFFSET_Y * (TblOne.Attributes.Count - (IsFKIsNguoiDung ? 1 : 0) - 3);
            }
            Result.AppendLine(TAB3 + "this.ClientSize = new System.Drawing.Size(733, " + ClientSize + ");");
            Result.AppendLine(TAB3 + "this.Controls.Add(this.panel1);");
            Result.AppendLine(TAB3 + "this.DoubleBuffered = true;");
            Result.AppendLine(TAB3 + "this.MaximizeBox = false;");
            Result.AppendLine(TAB3 + "this.MinimizeBox = false;");
            Result.AppendLine(TAB3 + "this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;");

            if (GlobalVariables.g_colComplex.Keys.Contains(TblOne.Name))
            {
                Result.AppendLine(TAB3 + "this.Name = \"Lập" + TblOne.Name + "\";");
                Result.AppendLine(TAB3 + "this.Text = \"Lập " + TblOne.Name + "\";");
            }
            else
            {
                Result.AppendLine(TAB3 + "this.Name = \"FrmQuanLy" + TblOne.Name + "\";");
                Result.AppendLine(TAB3 + "this.Text = \"Quản lý " + TblOne.Name + "\";");
            }

            Result.AppendLine(TAB3 + "this.Load += new System.EventHandler(this.FrmLap" + TblOne.Name + "_Load);");
            Result.AppendLine(TAB3 + "this.panel1.ResumeLayout(false);");
            Result.AppendLine(TAB3 + "this.panel1.PerformLayout();");
            Result.AppendLine(TAB3 + "((System.ComponentModel.ISupportInitialize)(this.dtgvData)).EndInit();");
            Result.AppendLine(TAB3 + "this.ResumeLayout(false);");
            Result.AppendLine(TAB2 + "}");

            return Result.ToString();
        }
    }
}
